package com.shuma.auth.controller;

import com.shuma.auth.entity.RestBean;
import com.shuma.auth.model.dto.ExchangeDataDto;
import com.shuma.auth.model.dto.ExchangeWayDataDto;
import com.shuma.auth.model.dto.SaleTop20DataDto;
import com.shuma.auth.service.OrdersService;
import com.shuma.auth.utils.Const;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestAttribute;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lele
 */
@Slf4j
@RestController
public class OrdersController {

    @Autowired
    private OrdersService ordersService;

    /**
     * 数据统计与分析兑换量
     * @param beginTime
     * @param endTime
     * @return
     */
    @PostMapping("product/exchangeData")
    public RestBean<ExchangeDataDto> exchangeDataAnalyze(@DateTimeFormat(pattern ="yyyy-MM-dd") LocalDate beginTime,
                                                         @DateTimeFormat(pattern ="yyyy-MM-dd")LocalDate endTime,
                                                         @RequestAttribute(Const.ATTR_USER_ID) Long id){
        log.info("用户id=========="+id);
        ExchangeDataDto exchangeDataDto = ordersService.exchangeDataAnalyze1(beginTime,endTime,id);
        return RestBean.success(exchangeDataDto);
    }

    /**
     * 销量Top20统计
     * @param beginTime
     * @param endTime
     * @return
     */
    @PostMapping("product/saleTop20Data")
    public RestBean<SaleTop20DataDto> saleTop20DataAnalyze(@DateTimeFormat(pattern ="yyyy-MM-dd")LocalDate beginTime,
                                                           @DateTimeFormat(pattern ="yyyy-MM-dd")LocalDate endTime,
                                                           @RequestAttribute(Const.ATTR_USER_ID) Long id){

        SaleTop20DataDto saleTop20DataDto = ordersService.saleTop20DataAnalyze(beginTime,endTime,id);
        return RestBean.success(saleTop20DataDto);
    }

    /**
     * 兑换方式统计
     * @param beginTime
     * @param endTime
     * @return
     */
    @PostMapping("product/exchangeWay")
    public RestBean<ExchangeWayDataDto> exchangeWayDataAnalyze(@DateTimeFormat(pattern ="yyyy-MM-dd")LocalDate beginTime,
                                                               @DateTimeFormat(pattern ="yyyy-MM-dd")LocalDate endTime,
                                                               @RequestAttribute(Const.ATTR_USER_ID) Long id){

        ExchangeWayDataDto exchangeWayDataDto = ordersService.exchangeWayDataAnalyze(beginTime,endTime,id);
        return RestBean.success(exchangeWayDataDto);
    }
}
